﻿using MassTransit;
using Microsoft.AspNetCore.Authorization;

namespace Sunxsh.Es.Application.Login;

/// <summary>
/// 用户登录
/// </summary>
[ApiRoute.App]
public class LoginController(ILogger<LoginController> logger)
{
    private readonly ILogger<LoginController> _logger = logger;

    /// <summary>
    /// 登录
    /// </summary>
    /// <returns></returns>
    [HttpGet("[action]")]
    [AllowAnonymous]
    public string Login()
    {
        var token = new TokenData(
            System.Guid.Parse("02e2ff08-b2b0-449d-a72a-46ce99ea6107"),
            "孙小双",
            "huasky"
        );
        AuthSession.Create(token);
        return token.ToTokenString();
    }

    /// <summary>
    /// 获取用户
    /// </summary>
    /// <returns></returns>
    [HttpGet("[action]")]
    public object GetStaff([FromServices] UserSession session)
    {
        var data = session.GetSessionData();
        return new { data.StaffId, data.StaffName };
    }

    /// <summary>
    /// 生成连续的GUID
    /// </summary>
    /// <returns></returns>
    [HttpGet("[action]")]
    [AllowAnonymous]
    public List<Guid> Guid()
    {
        var ww = new List<Guid>();
        for (int i = 0; i < 10; i++)
        {
            ww.Add(NewId.NextGuid());
        }
        return ww;
    }
}
